package com.wltt.product.ahuthr.executors;

import com.alibaba.excel.EasyExcel;
import com.wltt.product.ahuthr.excel.HouseFundData;
import com.wltt.product.ahuthr.excel.HouseFundListener;
import com.wltt.product.ahuthr.excel.SalaryLevelData;
import com.wltt.product.ahuthr.excel.SalaryLevelListener;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;

public class ImportSalaryLevelExecutor implements Runnable {

    private static final Logger logger = LogManager.getLogger(ImportSalaryLevelExecutor.class);

    private InputStream inputStream;
    private SalaryLevelListener salaryLevelListener;

    public ImportSalaryLevelExecutor(InputStream inputStream, SalaryLevelListener salaryLevelListener) {
        this.inputStream = inputStream;
        this.salaryLevelListener = salaryLevelListener;
    }

    @Override
    public void run() {
        try {
            EasyExcel.read(inputStream, SalaryLevelData.class, salaryLevelListener).sheet().doRead();
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }
}
